package org.jeecg.modules.compilation.util;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
public class LibreOfficeUtil {


    public static boolean wordConverterToPdf(String intFile, String outFile) throws IOException {

        try {
            String command = "";
            outFile = outFile.substring(0,outFile.lastIndexOf("/")+1);
            log.info("word地址：{}，pdf地址：{}",intFile,outFile);
            command =  "libreoffice7.4  --headless --invisible --convert-to pdf " +  intFile  + " --outdir  " + outFile;

            String result = CommandExecute.executeCommand(command);
            log.info("生成pdf的result=={}",result);

            if (result.equals("") || result.contains("writer_pdf_Export")) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return false;
    }

    public static boolean docxConverterToDoc(String intFile,String outFile) throws IOException {

        try {
            String command = "";
            outFile = outFile.substring(0,outFile.lastIndexOf("/")+1);
            log.info("doc地址：{}，docx地址：{}",intFile,outFile);
            command =  "libreoffice7.4  --headless --invisible --convert-to doc " +  intFile  + " --outdir  " + outFile;

            String result = CommandExecute.executeCommand(command);
            log.info("生成doc的result=={}",result);

            if (result.equals("") || result.contains("writer_pdf_Export")) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return false;
    }

}
